package org.example.design.observer.service.impl;

import org.example.design.observer.MinibusTargetService;
import org.example.design.observer.bean.LotteryResult;
import org.example.design.observer.service.LotteryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * @Classname LotteryServiceImpl
 * @Description TODO
 * @Date 2020/11/11 10:16 上午
 * @Created by xiangjd
 */
public class LotteryServiceImpl implements LotteryService {
    private Logger logger = LoggerFactory.getLogger(LotteryServiceImpl.class);

    private MinibusTargetService minibusTargetService = new MinibusTargetService();

    @Override
    public LotteryResult doDraw(String uid) {
        //摇号
        String lottery = minibusTargetService.lottery(uid);
        // 发短信
        logger.info("给用户 {} 发送短信通知(短信)：{}", uid, lottery);
        // 发MQ消息
        logger.info("记录用户 {} 摇号结果(MQ)：{}", uid, lottery);

        return new LotteryResult(uid, lottery, new Date());
    }
}
